﻿using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using Budjelar.Model.Entities;
using Budjelar.Repository.EF.Configuration;

namespace Budjelar.Repository.EF
{
    public class BudjelarDbContext : DbContext
    {
        public BudjelarDbContext()
        {
            ((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += (s, e) =>
            {
                var entity = e.Entity as Entity;
                if (entity != null)
                {
                    entity.State = State.Unchanged;
                }
            };
        }

        public DbSet<Artikal> Artikli { get; set; }

        public DbSet<VrstaArtikla> VrsteArtikala { get; set; }

        public DbSet<CenaArtikla> Cenovnik { get; set; }

        public DbSet<Prodavnica> Prodavnice { get; set; }

        public DbSet<Racun> Racuni { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new ArtikalConfiguration());
            modelBuilder.Configurations.Add(new VrsteArtikalaConfiguration());
            modelBuilder.Configurations.Add(new CenaArtiklaConfiguration());
            modelBuilder.Configurations.Add(new ProdavnicaConfiguration());
            modelBuilder.Configurations.Add(new RacunConfiguration());
            modelBuilder.Configurations.Add(new StavkaRacunaConfiguration());
            base.OnModelCreating(modelBuilder);
        }


    }
}